<?php
class ProductValidate extends Validate {
	protected function valid() {
		$result = array ();
		if (empty ( $this->param ['prodCoverId'] )) {
			$result ['result'] = 'error';
			$result ['error'] = '请上传图片';
			return $result;
		}
		if (empty ( $this->param ['prodName'] )) {
			$result ['result'] = 'error';
			$result ['error'] = '产品名称不能为空';
			return $result;
		}
		if (empty ( $this->param ['prodDesc'] )) {
			$result ['result'] = 'error';
			$result ['error'] = '产品描述不能为空';
			return $result;
		}
		if (empty ( $this->param ['prodUrl'] )) {
			$result ['result'] = 'error';
			$result ['error'] = '产品URL不能为空';
			return $result;
		}
		if (isset ( $this->param ['prodPrice'] )) {
			if (! preg_match ( "/^\d+(\.?\d{1,2})?$/", $this->param ['prodPrice'] )) {
				$result ['result'] = 'error';
				$result ['error'] = '产品价格应该是10位以内的正数,可以精确到两位小数';
				return $result;
			}
		}
		if (isset ( $this->param ['prodNowPrice'] )) {
			if (! preg_match ( "/^\d+(\.\d{1,2})?$/", $this->param ['prodNowPrice'] )) {
				$result ['result'] = 'error';
				$result ['error'] = '产品现价应该是10位以内的正数,可以精确到两位小数';
				return $result;
			}
		}
		if (isset ( $this->param ['prodSort'] ) && $this->param ['prodSort'] != null) {
			if (! preg_match ( "/^\d+$/", $this->param ['prodSort'] )
				|| $this->param ['prodSort']>99999) {
				$result ['result'] = 'error';
				$result ['error'] = '排序号只能为小于99999的正整数';
				return $result;
			}
		}
		if (isset ( $this->param ['prodAppraise'] ) && $this->param ['prodAppraise'] != null) {
			if (! preg_match ( "/^\d+$/", $this->param ['prodAppraise'] )) {
				$result ['result'] = 'error';
				$result ['error'] = '产品评价只能为正整数';
				return $result;
			}
		}
		if (isset ( $this->param ['prodRecomLevel'] ) && $this->param ['prodRecomLevel'] != null) {
			if (! preg_match ( "/^\d+$/", $this->param ['prodRecomLevel'] ) 
			|| $this->param ['prodRecomLevel'] > 127) {
				$result ['result'] = 'error';
				$result ['error'] = '推荐等级只能0到127的正整数';
				return $result;
			}
		}
		
		if (empty ( $this->param ['prodTypeC0'] ) || $this->param ['prodTypeC0'] == - 1) {
			$result ['result'] = 'error';
			$result ['error'] = '请选择产品分类';
			return $result;
		}
		$result ['result'] = 'success';
		return $result;
	}
}
?>